package com.huan;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Test9_udp_receiver {
    public static void main(String[] args) throws IOException {
        byte buf[] = new byte[3];
        DatagramPacket datagramPacket = new DatagramPacket(buf,buf.length);
        DatagramSocket socket = new DatagramSocket(3333);

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        while (true){
            socket.receive(datagramPacket);
            //将字节数组转成字符串输出
            System.out.println(new String(buf,0,datagramPacket.getLength()));
        }
    }
}
